<?php
require('../api.inc.php');
include_once( ROOT . 'sdk/saetv2.ex.class.php' );

$o = new SaeTOAuthV2( SINAWB_AKEY , SINAWB_SKEY );

if (isset($_REQUEST['code'])) {
    $keys = array();
    $keys['code'] = $_REQUEST['code'];
    $keys['redirect_uri'] = SINAWB_CALLBACK_URL;
    try {
        $token = $o->getAccessToken( 'code', $keys );
    } catch (OAuthException $e) {
        
    }
}

if ($token) {
    $_SESSION['token'] = $token;
    User::add($token['access_token'], $token['uid']);

    echo '登录成功';
} else {
    echo '登录失败';
}
